package top.lshaci.learning.springboot.rabbitmq.controller;

import lombok.AllArgsConstructor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.lshaci.framework.common.model.JsonResponse;
import top.lshaci.learning.springboot.rabbitmq.model.SpringBootMessage;

/**
 * PublisherController
 *
 * @author lshaci
 * @since 1.0.0
 */
@RestController
@AllArgsConstructor
@RequestMapping("publisher")
public class PublisherController {

    private final RabbitTemplate rabbitTemplate;

    @GetMapping("publish")
    public JsonResponse<Object> publish() {
        String exchange = "springboot.direct";
        String routingKey = "springboot.direct";
        SpringBootMessage message = new SpringBootMessage();
        message.setName("spring boot");
        rabbitTemplate.convertAndSend(exchange, routingKey, message);

        return JsonResponse.success();
    }

    @GetMapping("delay")
    public JsonResponse<Object> delay(String message) {
        String exchange = "deal.exchange";
        String routingKey = "deal.message";
        rabbitTemplate.convertAndSend(exchange, routingKey, message);

        return JsonResponse.success();
    }


    @GetMapping("/order/create")
    public JsonResponse<Object> orderCreate(String message) {
        String exchange = "order-event-exchange";
        String routingKey = "order.create.order";
        rabbitTemplate.convertAndSend(exchange, routingKey, message);

        return JsonResponse.success();
    }

}
